<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="communityName" align="center" label="小区名" />
        <el-table-column prop="complainTypeId"align="center" label="投诉类型" >
          <template slot-scope="scope">
            {{ dict.label.complain_type[scope.row.complainTypeId] }}
          </template>
        </el-table-column>
        <el-table-column prop="complainContent" align="center" label="投诉内容" />
        <el-table-column prop="remark" align="center" label="备注" />
        <el-table-column label="图片" align="center" width="400">
          <template slot-scope="scope">
            <el-button v-if="scope.row.id && scope.row.fileUrls && scope.row.fileUrls.length !== 0" size="small" type="info" @click="dialogDetail(scope.row.fileUrls)">查看图片</el-button>
            <el-dialog
              :visible.sync="dialogDetailVisible"
              width="50%"
              :before-close="handleCloseDetail"
            >
              <el-carousel indicator-position="outside" :interval="0" height="400px">
                <el-carousel-item v-for="item in paths" :key="item">
                  <el-image
                    style="width: 100%; height: 100%"
                    :src="item"
                    fit="contain"
                  />
                </el-carousel-item>
              </el-carousel>
            </el-dialog>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" align="center" label="创建日期" />
        <el-table-column prop="createBy" align="center" label="创建者" />
        <!--        <el-table-column v-if="checkPer(['admin','complainInfo:edit','complainInfo:del'])" label="操作" width="150px" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudComplainInfo from '@/api/system/complainInfo'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, createTime: null, updateTime: null, createBy: null, updateBy: null, deleted: null, xqId: null, complainTypeId: null, complainContent: null, remark: null, fileUrl: null }
export default {
  name: 'ComplainInfo',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['complain_type'],
  cruds() {
    return CRUD({ title: 'Complain', url: 'api/complain/page', idField: 'id', sort: 'id,desc', crudMethod: { ...crudComplainInfo }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'complainInfo:add'],
        edit: ['admin', 'complainInfo:edit'],
        del: ['admin', 'complainInfo:del']
      },
      rules: {
      },
      currentImage: '',
      dialogVisible: false,
      paths: [],
      dialogDetailVisible: false
    }
  },
  methods: {
    handlePictureCardPreview(index, paths) {
      this.currentImage = paths[index]
      this.dialogVisible = true
    },
    dialogDetail(paths) {
      this.paths = paths
      this.dialogDetailVisible = true
    },
    // 关闭详情进行操作
    handleCloseDetail() {
      this.paths = []
      this.dialogDetailVisible = false
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.optShow.add = false
      this.crud.optShow.edit = false
      this.crud.optShow.del = false
      this.crud.optShow.download = false
      return true
    }
  }
}
</script>

<style scoped>

</style>
